﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for RolesBLL
/// </summary>
public class RolesBLL
{
	public RolesBLL()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public static Roles rowToDto(dsRoles.RolesDSRow RolesRow)
    {

        Roles objRoles = new Roles();
        objRoles.IRol_id = RolesRow.iRol_id;
        objRoles.SNombre = RolesRow.sNombre;



        return objRoles;
    }
    public static List<Roles> GetAll()
    {
        List<Roles> ListaDeRoles = new List<Roles>();
        try
        {



            dsRolesTableAdapters.RolesDSTableAdapter RolesAdapter
                = new dsRolesTableAdapters.RolesDSTableAdapter();
            dsRoles.RolesDSDataTable RolesDataTable = RolesAdapter.GetAll_Roles();

            foreach (dsRoles.RolesDSRow row in RolesDataTable)
            {
                Roles objRoles = rowToDto(row);
                ListaDeRoles.Add(objRoles);
            }
        }
        catch (Exception ex)
        {

            //Manejar Excepcion
        }
        return ListaDeRoles;
    }
    public static Roles GetByPK(int pk)
    {

        try
        {

            dsRolesTableAdapters.RolesDSTableAdapter RolesAdapter
                = new dsRolesTableAdapters.RolesDSTableAdapter();
            dsRoles.RolesDSDataTable RolesDataTable
                = RolesAdapter.GetByPk_Roles(pk);

            Roles objRoles = rowToDto(RolesDataTable[0]);
            return objRoles;
        }
        catch (Exception ex)
        {

            //Manejar Excepcion
        }
        return null;
    }

    public static int InsertarRoles(string sNombre)
    {

        try
        {

            dsRolesTableAdapters.RolesDSTableAdapter RolesAdapter
                = new dsRolesTableAdapters.RolesDSTableAdapter();


            int? nuevaPK = 0;

            RolesAdapter.Insertar_Roles(sNombre, ref nuevaPK);

            return (int)nuevaPK;
        }
        catch (Exception ex)
        {

            //Manejar Excepcion
        }
        return 0;
    }

    public static bool ModificarRoles(int pk, string sNombre)
    {

        try
        {

            dsRolesTableAdapters.RolesDSTableAdapter RolesAdapter
                = new dsRolesTableAdapters.RolesDSTableAdapter();

            RolesAdapter.Modificar_Roles(pk, sNombre);


            return true;
        }
        catch (Exception ex)
        {

            //Manejar Excepcion
        }
        return false;
    }

    public static bool EliminarRoles(int pk)
    {

        try
        {

            dsRolesTableAdapters.RolesDSTableAdapter RolesAdapter
                = new dsRolesTableAdapters.RolesDSTableAdapter();

            RolesAdapter.Eliminar_Roles(pk);


            return true;
        }
        catch (Exception ex)
        {

            //Manejar Excepcion
        }
        return false;
    }

}